home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / xcode / pcx.asm < prev    next >
Encoding:
Assembly Source File  |  1993-10-18  |  2.4 KB  |  92 lines

  1.  
  2. ;----------------------------------------------------------------------------:
  3. ; Code to deal with .PCX and .PCC files on VGA                                 :
  4. ;    SILVERMOON                                                                 :
  5. ; (C) John Connors                    1993                                     :
  6. ;----------------------------------------------------------------------------:
  7.  
  8.     IDEAL
  9.     MODEL    HUGE,C
  10.     P286N
  11.     
  12.     INCLUDE "STRUCTS.INC"
  13.  
  14.     PUBLIC    decode_pcx_buffer
  15.     
  16. PCX_Header_Size EQU 128
  17. PCX_CLUT_Size    EQU 256*3
  18.  
  19. ;----------------------------------------------------------------------------:
  20. ;            CODE SEGMENT                                                     :
  21. ;----------------------------------------------------------------------------:
  22.  
  23.  
  24.     CODESEG
  25.     
  26. ;----------------------------------------------------------------------------:
  27. ; decode_pcx_buffer(char *dest,char *source)                                 :
  28. ;                                                                             :
  29. ; Given that a .PCX file has been read into File_Segment, decode the binary  :
  30. ; image data into the 32-bit data segment at Screen_Buffer                     : 
  31. ;----------------------------------------------------------------------------:
  32.  
  33. PROC decode_pcx_buffer 
  34.     ARG     destination_buffer:DWORD,source_buffer:DWORD
  35.     
  36.     PUSH    DS
  37.     PUSH    SI
  38.     PUSH    DI
  39.         
  40.     LDS     SI,[source_buffer]                    ; set up File Segment source
  41.     LES     DI,[destination_buffer]             ; set up Screen buffer dest.
  42.     XOR     CX,CX                                ; clear counter
  43.     MOV     DX,[(PCX_Header PTR SI).X2]         ; DX = x dimension of picture
  44.     SUB     DX,[(PCX_Header PTR SI).X1]
  45.     INC     DX
  46.     TEST    DX,1                                ; allow for deluxe paint quirk
  47.     JZ        SHORT @@Not_Odd_Width
  48.     INC     DX
  49. @@Not_Odd_Width:
  50.     MOV     AX,[(PCX_Header PTR SI).Y2]         ; AX = y dimesnion of picture
  51.     SUB     AX,[(PCX_Header PTR SI).Y1]
  52.     INC     AX
  53.     MUL     DX                                    ; AX = DX * AX (size of image)
  54.     MOV     DX,AX
  55.     ADD     DX,DI                                ; DX = offset of last byte
  56.     ADD     SI,PCX_Header_Size                    ; point to start of data
  57.  
  58. Decode_Next_PCX_Byte:
  59.     CMP     DX,DI                                ; end of encoded data?
  60.     JBE     SHORT Decoded_PCX
  61.     LODSB                                        ; get next byte
  62.     MOV     AH,AL
  63.     AND     AH,11000000b                        ; is it a run ?
  64.     CMP     AH,11000000b
  65.     JNZ     SHORT @@Not_Compressed                ; nope, branch
  66.     MOV     AH,AL
  67.     AND     AH,00111111b                        ; AH is run length
  68.     LODSB                                        ; AL is colour byte
  69.     MOV     CL,AH     
  70.     TEST    CL,00111111b                        ; run of zero ?
  71.     JZ        SHORT Decode_Next_PCX_Byte            ; yes, forget it
  72.     
  73. @@Decode_Run:
  74.     STOSB
  75.     LOOP    @@Decode_Run
  76.     JMP     SHORT Decode_Next_PCX_Byte
  77.  
  78. @@Not_Compressed:
  79.     STOSB
  80.     JMP     SHORT Decode_Next_PCX_Byte 
  81.  
  82. Decoded_PCX:
  83.     POP     DI
  84.     POP     SI
  85.     POP     DS
  86.  
  87.     RET
  88. ENDP    decode_pcx_buffer
  89.  
  90.  
  91.     END
  92.